<!--
 * @Author: your name
 * @Date: 2020-12-27 12:48:22
 * @LastEditTime: 2021-03-26 18:17:17
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \white-jotter-blog-vue\src\views\library\index.vue
-->
<template>
  <div class="Library">
    <el-container>
      <el-aside style="width: 200px;">
        <library-side-menu @indexSelect="getBooksBycategory" ref="sideMenu"></library-side-menu>
      </el-aside>
      <el-main>
        <library-books id="books" ref="books"></library-books>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import LibrarySideMenu from "components/content/library/LibrarySideMenu";
import LibraryBooks from "components/content/library/LibraryBooks";
export default {
  name: "Library",
  metaInfo: {
    title: "图书馆",
  },
  data() {
    return {};
  },
  components: {
    LibraryBooks,
    LibrarySideMenu,
  },
  methods: {
    // 监听侧边栏的点击，加载图书
    async getBooksBycategory() {
      let cid = this.$refs.sideMenu.cid;
      if (cid === "0") {
        const res = await this.$http.get("/library/books");
        this.$refs.books.bookList = res.data;
        return;
      }
      const res = await this.$http.get(`library/books/category/${cid}`);
      if (res.status === 200) this.$refs.books.bookList = res.data;
    },
  },
};
</script>

<style lang="less" scoped>
  
</style>
